package com.zhida.jiyangcenter.order

import android.os.Bundle
import androidx.fragment.app.FragmentManager
import androidx.fragment.app.FragmentPagerAdapter
import androidx.lifecycle.LifecycleService
import androidx.lifecycle.lifecycleScope
import chooongg.base.annotation.ContentLayout
import chooongg.base.annotation.TitleBar
import chooongg.base.utils.logE
import com.google.gson.Gson
import com.zhida.jiyangcenter.R
import com.zhida.jiyangcenter.api.ExpressEntity
import com.zhida.jiyangcenter.api.KdniaoTrackQueryAPI
import com.zhida.jiyangcenter.mian.BaseActivity
import com.zhida.jiyangcenter.mian.BaseFragment
import com.zhida.jiyangcenter.order.fragment.ShopOrderFragment
import com.zhida.jiyangcenter.utils.request
import kotlinx.android.synthetic.main.tablayout_viewpage.*
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import org.json.JSONObject

@TitleBar(false)
@ContentLayout(R.layout.tablayout_viewpage)
class ShopOrderListActivity : BaseActivity() {
    private lateinit var adapter: Adapter
    private val fragments = ArrayList<BaseFragment>()

    private class Adapter(fm: FragmentManager, val fragments: ArrayList<BaseFragment>) :
        FragmentPagerAdapter(fm) {
        override fun getItem(position: Int) = fragments[position]
        override fun getCount() = fragments.size
        override fun getPageTitle(position: Int) = fragments[position].getTitle()
    }

    override fun initConfig(savedInstanceState: Bundle?) {
        title_bar.navigationIcon(R.drawable.iv_back_fill) {
            finish()
        }
        title_bar.title("我的商城")
//        title_bar.operationIcon(R.drawable.iv_comment_sreach) {
//
//        }
        fragments.add(ShopOrderFragment(-1))
        fragments.add(ShopOrderFragment(0))
        fragments.add(ShopOrderFragment(2))
        fragments.add(ShopOrderFragment(5))

        adapter = Adapter(
            supportFragmentManager,
            fragments
        )
        view_pager.adapter = adapter
        view_pager.offscreenPageLimit = fragments.size - 1
        tab_layout.setupWithViewPager(view_pager)
    }
}